package com.cf.auth.config;

import cn.hutool.crypto.digest.DigestUtil;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * 自定义md5编码器，使用sha1(md5("xxxx"))
 * @author ChenFeng
 * @date 2021/11/9 2:31 下午
 * @description
 */
public class Md5PasswordEncoder implements PasswordEncoder {

    @Override
    public String encode(CharSequence charSequence) {
        String str = DigestUtil.sha1Hex(DigestUtil.md5Hex(String.valueOf(charSequence)));
        return str;
    }

    @Override
    public boolean matches(CharSequence charSequence, String s) {
        return DigestUtil.sha1Hex(DigestUtil.md5Hex(String.valueOf(charSequence))).equals(s);
    }
}
